#include<bits/stdc++.h>
using namespace std;
int n;
long long ans;
long long a[200010],s[200010];
void dfs(int dep,int co,long long tol,long long lr,long long lb)
{
    // cout<<dep<<" "<<co<<" "<<tol<<" "<<lr<<" "<<lb<<" "<<endl;
    if(dep==n)
    {
        ans=max(ans,tol);
        return;
    }
    if(tol+(s[n]-s[dep])<=ans)
        return;
    if(a[dep+1]==lr)
    {
        dfs(dep+1,0,tol+a[dep+1],a[dep+1],lb);
    }else  
        dfs(dep+1,0,tol,a[dep+1],lb);
    if(a[dep+1]==lb)
        dfs(dep+1,1,tol+a[dep+1],lr,a[dep+1]);
    else    
        dfs(dep+1,1,tol,lr,a[dep+1]);
}
int main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int T;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
        {
            scanf("%lld",&a[i]);
            s[i]=s[i-1]+a[i];
        }
        ans=0;
        dfs(1,0,0,a[1],0);
        printf("%lld\n",ans);
    }
    return 0;
}